package edu.gatech.cs2340.group7.wheresmystuffapp.presenters;

import edu.gatech.cs2340.group7.wheresmystuffapp.model.CustomDate;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.DataManager;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.DatabaseHelper;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.FoundItem;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.IReportItemPresenter;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.Item;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.ItemLocation;
import edu.gatech.cs2340.group7.wheresmystuffapp.model.CustomLocation;
import edu.gatech.cs2340.group7.wheresmystuffapp.views.ReportFoundItemView;

/**
 * Presenter for reporting a found item
 * @author tbowling3
 *
 */
public class ReportFoundItemPresenter extends IReportItemPresenter {

	public ReportFoundItemPresenter(ReportFoundItemView view) {
		super(view);
	}

	/**
	 * Adds a found item to the database
	 * @param itemName the name of the item
	 * @param description the item's description
	 * @param category the category of the item
	 * @param date the date that the item was found
	 * @param location the location that the item was found
	 * @param pic - unused for now
	 * @return -1 if there was an error adding the item to the database
	 */
	public long addItem(String itemName, String description, String category, String date, ItemLocation il, byte[] pic) {
		long out = -1;
		if (itemName == null){
			//myView.setAddItemResult("Please enter a name");
			return -1;
		}
		if (description == null){
			//myView.setAddItemResult("Please enter a description");
			return -1;
		}
		if(date == null){
			//myView.setAddItemResult("Please enter a date");
			return -1;
		}
		if(il == null){
			//myView.setAddItemResult("Please enter a location");
			return -1;
		}
		
		if(category.equals("empty")){
			//myView.setAddItemResult("Please select a category");
			return -1;
		}
		
		CustomDate custDate = new CustomDate(date);
		
		
		
		String username = DataManager.getCurrentAccountName();

		Item created = new FoundItem(username, itemName, category, description, il,
				custDate, pic);
		out = helper.addItem(created);//helper.addItem(created);

		//myView.setAddItemResult("Item Added!");
		return out;
	}
	
	/**
	 * Adds a found item to the database
	 * @param itemName the name of the item
	 * @param description the item's description
	 * @param category the category of the item
	 * @param date the date that the item was found
	 * @param pic - unused for now
	 * @return -1 if there was an error adding the item to the database
	 */
	public long addItem(String itemName, String description, String category, String date, byte[] pic) {
		ItemLocation il = getCurrentLocation();	
		return addItem(itemName, description, category, date, il, pic);
	}
	

	

}
